// SSCADA.h
#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <memory>
#include <mutex>
#include <ctime>
#include <iomanip>
#include <map>

struct MeasPoint {
    std::string id;
    time_t timestamp;
    float value;
};

class SSCADA {
public:
    static SSCADA& getInstance();
    
    void loadMeasurement(const std::string& filename = "data.csv");
    void printStatInfo() const;  //const成员函数，不会修改成员变量
    void printStatInfo(time_t start, time_t end) const; //重载

    // 删除拷贝构造函数和赋值运算符
    SSCADA(const SSCADA&) = delete;
    SSCADA& operator=(const SSCADA&) = delete;
    // 时间基准（当天0点）
    time_t baseTime = 0;

private:
    SSCADA() = default; // 私有构造函数
    
    // 辅助函数
    int timeToIndex(time_t timestamp) const; 
    time_t indexToTime(int index) const;
    
    // 数据存储：测点ID -> [288个时间点的值]
    // std::unordered_map<std::string, std::array<float, 288>> measurements;
    std::map<std::string, std::array<float, 288>> measurements;
    
    // 线程安全
    mutable std::mutex mtx; //mutable修饰的成员变量可以在const成员函数中修改
};